import { ENUM_CLIP, ENUM_STATUS, ENUM_UI } from "../GbzEnum";
import GbzInstance from "../GbzInstance";
import GbzAudioManager from "../manager/GbzAudioManager";
import GbzDataManager from "../manager/GbzDataManager";
import GbzSdkManager from "../manager/GbzSdkManager";
import BaseLayer from "./GbzBaselayer";

const { ccclass, property } = cc._decorator;

@ccclass
export default class GbzExitLayer extends BaseLayer {

    panel: cc.Node = null
    btn_submit: cc.Node = null
    btn_close: cc.Node = null
    btn_share: cc.Node = null

    onLoad() {
        this.panel = cc.find('style/panel', this.node)
        this.btn_submit = cc.find('buttons/btn_submit', this.panel)
        this.btn_submit.on('click', this.onSubmit, this)

        this.btn_close = cc.find('btn_close', this.panel)
        this.btn_close.on('click', this.onClose, this)

        this.btn_share = cc.find('buttons/btn_share', this.panel)
        this.btn_share.on('click', this.onShare, this)
    }

    onDestroy() {
        this.btn_submit.off('click', this.onSubmit, this)
        this.btn_close.off('click', this.onClose, this)
        this.btn_share.off('click', this.onShare, this)
    }

    onEnable() {
        this.zoom(this.panel)
        GbzSdkManager.ins.showBanner(true)
    }

    onDisable() {
        GbzSdkManager.ins.showBanner(false)
    }
    onSubmit() {
        GbzAudioManager.ins.play(ENUM_CLIP.GAME_CLICK)
        GbzDataManager.ins.status = ENUM_STATUS.UNRUN
        GbzInstance.uiMgr.setMainCountDown(false)
        GbzInstance.uiMgr.toggle(ENUM_UI.LAYER_MAIN, false)
        GbzInstance.uiMgr.toggle(ENUM_UI.LAYER_EXIT, false)
        GbzInstance.uiMgr.toggle(ENUM_UI.LAYER_MENU)
    }

    onClose() {
        GbzAudioManager.ins.play(ENUM_CLIP.GAME_CLICK)
        GbzInstance.uiMgr.toggle(ENUM_UI.LAYER_EXIT, false)
    }

    onShare() {
        GbzAudioManager.ins.play(ENUM_CLIP.GAME_CLICK)
        if (GbzSdkManager.ins.platform()) GbzSdkManager.ins.activeShare()
    }
}
